package com.kangtushizhe.handler;

import com.alibaba.fastjson2.JSON;
import com.kangtushizhe.entities.CommonResult;
import com.kangtushizhe.utils.WebUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class AppAccessDenyHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        CommonResult result = new CommonResult<>(403, "未具有权限");
        String responseJson = JSON.toJSONString(result);
        WebUtil.renderString(response,responseJson);
    }
}
